fix(version): read package version at runtime instead of npm env var - #5
Merged
Conversation
The startup banner and /health endpoint fell back to a hardcoded "0.1.0" whenever the proxy was run outside an npm script (node dist/proxy.js, make start, or a globally installed binary) because npm_package_version is only set by npm/pnpm run. Add a version module that reads package.json next to the module at runtime, so all run modes report the real version.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The startup banner and the
/healthendpoint reportedv0.1.0instead of the real installed version whenever the proxy was started outside an npm script — e.g.node dist/proxy.js,make start, or a globally installed binary.Root cause
src/proxy.tsandsrc/server.tsreadprocess.env.npm_package_version, which is only set bynpm/pnpmrun scripts. In all other run modes it isundefined, so the hardcoded"0.1.0"fallback was used.Fix
src/version.ts: readspackage.jsonlocated next to the module at runtime (viaimport.meta.url), so it resolves correctly in all run modes (tsx src/,node dist/, global binary). Falls back to the env var, then0.0.0.getProxyVersion()in the startup banner (src/proxy.ts) and/health(src/server.ts).Testing
tests/version.test.tsdeletesnpm_package_versionto reproduce the bug and asserts the real version is returned./healthtest now assertsversionmatchespackage.json.tsc --noEmitclean.node dist/proxy.jsprintsv0.3.0and/healthreturns{"status":"ok","version":"0.3.0"}.